package com.yoo.module_base.utils

import android.app.ActivityManager
import android.content.Context
import java.util.*
import java.util.concurrent.atomic.AtomicLong
import kotlin.system.exitProcess

/**
 * @ClassName: AppUtil
 * @Description:
 * @Author: You
 */
object AppUtil {
    /**
     * 彻底关闭整个APP
     */
    fun exitApp(context: Context) {
        val systemService =
            context.applicationContext.getSystemService(Context.ACTIVITY_SERVICE) as? ActivityManager
        systemService?.appTasks?.forEach {
            it.finishAndRemoveTask()
        }
        android.os.Process.killProcess(android.os.Process.myPid())
        exitProcess(0)
        System.gc()
    }

    /**
     * 获取导航栏高度
     */
    fun getNavigationBarHeight(context: Context): Int {
        val resources = context.resources
        val resourceId =
            context.resources.getIdentifier("navigation_bar_height", "dimen", "android")
        return resources.getDimensionPixelSize(resourceId)
    }

    fun dip2px(var0: Context?, var1: Float): Int {
        return if (null == var0) {
            0
        } else {
            val var2 = var0.resources.displayMetrics.density
            (var1 * var2).toInt()
        }
    }

    fun getRandomStr(): String {
        return System.currentTimeMillis().toString() + UUID.randomUUID().toString()
    }

    private var id = AtomicLong(0)

    fun getRandomLong(): Long {
        return "${System.currentTimeMillis()}${id.incrementAndGet()}".toLong()
    }
}